package sparkExamples.exerciseDemo

import org.apache.spark.{SparkConf, SparkContext}

object ExerciseDemo01 {

  def main(args: Array[String]): Unit = {

    val conf = new SparkConf().setAppName("ExerciseDemo").setMaster("local[*]")
    val sparkContext = new SparkContext(conf)

    val txtRDD = sparkContext.textFile("src\\main\\scala\\data\\exerciseData.txt")


//    val tupled = txtRDD.map(line => {
//      val fields = line.split(" ")
//      val classid = fields(0)
//      val name = fields(1)
//      val age = fields(2)
//      val sex = fields(3)
//      val course = fields(4)
//      val score = fields(5)
//      (classid, name, age, sex, course, score)
//    })
//
//    tupled.collect().foreach(println)

    val peopleNum = txtRDD.map {
      line => {
        val strings = line.split(" ")
        strings(1)
      }
    }.distinct().count()
    println(peopleNum)


    sparkContext.stop()
  }

}
